{extend name="platform/base" /}
{block name="resources"/}
<style>
.modal-infp-style{width:100%;margin:10px auto;}
.modal-infp-style table{width:100%;}
.modal-infp-style table tr td{border: 1px solid #e5e5e5;padding: 10px;}
.ns-main{margin-top: 0;}
.img-container{    height: 90px;line-height: 90px; width: 90px;text-align: center;margin-left: 0 !important;display: inline-block;}
.img-container,.img-mid  img{display: inline-block !important;vertical-align: middle !important;max-width: 100% !important;max-height: 100% !important;height: auto !important;}
.img-mid{height: 120px;line-height: 120px; width: 120px;text-align: center;margin-left: 0 !important;display: inline-block;}

.fa {display: grid;}
.text-active, .active>.text {display: none;}
.searchable-select-item.selected ,.searchable-select-item.hover {background: #65bd77!important;}
.searchable-select{line-height: 1.2!important; border-color: #d9d9d9!important;}
.searchable-select-dropdown{border: 1px solid #d9d9d9 !important;}
.searchable-select-holder{
	border: 1px solid #d9d9d9 !important;
	-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0) !important;;
    box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0) !important;;
    -webkit-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
}
.searchable-select-holder{border-radius: 2px!important;}

</style>
{/block}
 {block name="main"}
<div class="row padder-v">
	<div class="col-sm-9">

	</div>
	
	<div class="col-sm-2">
		<div class="input-group">
			<input type="text" class="input-sm form-control" id="search_text"
				placeholder="请输入专题活动名称">
		</div>
	</div>
	<div class="col-sm-1">
		<div class="input-group">
			<span class="input-group-btn">
				<button class="btn btn-sm btn-default"  id="search_text" type="button"
					onclick="LoadingInfo(1)">搜索</button>
			</span>
		</div>
	</div>
</div>
<section class="panel panel-default">
		<table class="table table-striped b-light text-sm">
			<colgroup>
				<col style="width: 2%;">
				<col style="width: 10%;">
				<col style="width: 15%;">
				<col style="width: 15%;">
				<col style="width: 15%;">
				<col style="width: 15%;">
				<col style="width: 15%;">
			</colgroup>
			<thead>
				<tr align="center">
					<th></th>
					<th align="left">类型</th>
					<th align="left">标题</th>
					<th align="left">接收账号</th>
					<th>创建时间</th>
					<th>发送时间</th>
					<th>状态</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody  id="list">
				
			</tbody>
		</table>

	{include file="platform/page" /}
</section>
{/block} 
{block name="script"}
<link rel="stylesheet" type="text/css" href="__ROOT__/public/admin/css/plugin/jquery.searchableSelect.css">
<script src="__ROOT__/public/admin/js/plugin/jquery.searchableSelect.js"></script>
<script src="__STATIC__/js/BootstrapMenu.min.js"></script>

<script type="text/javascript">

$(function(){
	LoadingInfo(1);
});

 function LoadingInfo(page_index) {
		var search_text = $("#search_text").val();
		var type = "{$type}";
		var status = "{$status}";
		$.ajax({
			type : "post",
			url : "{:__URL('PLATFORM_MAIN/config/notifylist')}",
			data : { "page_index" : page_index, "page_size" : $("#showNumber").val(), "search_text" : search_text, "type" : type,"status" : status },
			success : function(data) {
				$("#total_count_num").text(data["total_count"]);
				$("#page_count_num").text(data["page_count"]);
				$("#page_count").val(data["page_count"]);
				$("#pageNumber a").remove();
				var html = '';
				if (data["data"].length > 0) {
					for (var i = 0; i < data["data"].length; i++) {
						//短信记录结果
						switch(parseInt(data['data'][i]['is_send']))
						{
							case 0:
								var status_name = '未发送';
								break;
							case 1:
								var status_name = '发送成功';
								break;
							case -1:
								var status_name = '发送失败';
								break;
						}
					
						switch(parseInt(data['data'][i]['send_type'])){
						case 1:
							var type_name = '短信';
							break;
						case 2:
							var type_name = '邮件';
							break;
						}
						
						html += '<tr align="center">';
						html += '<td></td>';
						html += '<td align="left">' + type_name + '</td>';
						html += '<td align="left">' + data["data"][i]["notice_title"] + '</td>';
						html += '<td align="left">' + data["data"][i]["send_account"] + '</td>';
						html += '<td>' + timeStampTurnTime(data["data"][i]["create_date"]) + '</td>';
						html += '<td>'+ timeStampTurnTime(data["data"][i]["send_date"]) + '</td>';
						html += '<td>'+ status_name +'</td>';
						html += '<td>';

						html += '<a href="javascript:void(0);"onclick="notifyDetailInfo('+data["data"][i]["id"]+')">详情</a>&nbsp;';
						html += '</td> ';
						html += '</tr>';
					}
				} else {
					var html = '<tr align="center"><td colspan="9">暂无符合条件的数据记录</td></tr>';
				}
					
				$("#list").html(html);
				var totalpage = $("#page_count").val();
				if (totalpage == 1) {
					changeClass("all");
				}
				var $html = pagenumShow(jumpNumber,totalpage,{$pageshow})
				$("#pageNumber").append($html);
				$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
				}
		});
	}

function searchData(){
	LoadingInfo(1);
}

function notifyDetailInfo(id){
	$("#notifyDetailInfo").modal("show");
	$.ajax({
		type:"post",
		url : "{:__URL('PLATFORM_MAIN/config/notifydetail')}",
		data : { "id" : id },
		success : function(data) {
			$("#user_name").text(data["send_account"]);
			$("#notice_title").text(data["notice_title"]);
  			$("#create_date").text(timeStampTurnTime(data['create_date']));
 			$("#send_date").text(timeStampTurnTime(data['send_date']));
			
			$("#notice_title").text(data["notice_title"]);
			$("#notice_title").text(data["notice_title"]);

			//短信记录结果
			switch(parseInt(data['is_send']))
			{
				case 0:
					var status_name = '未发送';
					break;
				case 1:
					var status_name = '发送成功';
					break;
				case -1:
					var status_name = '发送失败';
					break;
			}
		
			switch(parseInt(data['send_type']))
			{
				case 1:
					var type_name = '短信';
					break;
				case 2:
					var type_name = '邮件';
					break;
			}
			
			$("#status").text(status_name);
			$("#type").text(type_name);
			if(data["send_type"] == 1){
				var notice_context = JSON.parse(data["notice_context"]);
				var send_message = JSON.parse(data["send_message"]);
				html = '';
				$.each(notice_context, function(i, n)
                {
                	html += i.toString() + ": " + n + "<br>";      
                });
				$("#notice_context").html(html);
				var send_config = JSON.parse(data["send_config"]);
				if(send_config.sms_type == 0){
					//旧用户
					$("#send_message").text(send_message.sub_msg);
				}else if(send_config.sms_type == 1){
					//新用户
					$("#send_message").text(send_message.Message);
				}
			}else if(data["send_type"] == 2){
				$("#notice_context").html(data["notice_context"]);
				$("#send_message").text(status_name);
			}
			$("#notifyDetailInfo table tr.rule").remove();

		}
	})
}

$('#notifyDetailInfo').on('hidden.bs.modal', function (e) {
  	removeContent();
})


function removeContent(){
	$("#status").text("");
	$("#type").text("");
	$("#notice_context").html("");
	$("#send_message").text("");
	$("#user_name").text("");
	$("#notice_title").text("");
	$("#create_date").text("");
	$("#send_date").text("");
	$("#notice_title").text("");
	$("#notice_title").text("");
}
</script>
{/block}